﻿//-----------------------------------------------------------------------
// <copyright file="ContactManagerDependencyRegistry.cs" company="OverrideThis">
//     Copyright (c) 2010 OverrideThis.com
// </copyright>
//-----------------------------------------------------------------------
namespace OverrideThis.ContactManager.Infrastructure.IoC
{
    using OverrideThis.ContactManager.Infrastructure.Repository.Cfg;
    using OverrideThis.Core.Infrastucture.Repository;
    using OverrideThis.Core.Infrastucture.Repository.Impl;
    using OverrideThis.Core.Services;
    using StructureMap.Configuration.DSL;

    public class ContactManagerDependencyRegistry : Registry
    {
        public ContactManagerDependencyRegistry(string connKey)
        {
            this.For<NhSessionFactory>()
                .Singleton()
                .Use(ctx => new NhSessionFactory(new ContactManagerNhSessionFactoryCfg(connKey)));
            this.For<IRepository>()
                .Use(ctx => new NhRepository(ctx.GetInstance<NhSessionFactory>().Get()));
            this.Scan(
                scan => {
                    scan.AddAllTypesOf<IService>();
                    scan.WithDefaultConventions();
                });
        }
    }
}